home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d8 / serial_1.arc / SERIAL.H < prev   
C/C++ Source or Header  |  1990-05-14  |  6KB  |  194 lines

  1. /*---------------------------------------------------------------------*
  2.    FILENAME:                     SERIAL.H
  3.  
  4.                   Some definitions used by SERIAL.C
  5.  
  6.  *--------------------------------------------------------------------*/
  7.  
  8. #define COM1            1
  9. #define COM2            2
  10. #define COM1BASE        0x3F8   /*  Base port address for COM1  */
  11. #define COM2BASE        0x2F8   /*  Base port address for COM2  */
  12.  
  13. /*
  14.     The 8250 UART has 10 registers accessible through 7 port addresses.
  15.     Here are their addresses relative to COM1BASE and COM2BASE. Note
  16.     that the baud rate registers, (DLL) and (DLH) are active only when
  17.     the Divisor-Latch Access-Bit (DLAB) is on. The (DLAB) is bit 7 of
  18.     the (LCR).
  19.  
  20.     o TXR Output data to the serial port.
  21.     o RXR Input data from the serial port.
  22.     o LCR Initialize the serial port.
  23.     o IER Controls interrupt generation.
  24.     o IIR Identifies interrupts.
  25.     o MCR Send contorl signals to the modem.
  26.     o LSR Monitor the status of the serial port.
  27.     o MSR Receive status of the modem.
  28.     o DLL Low byte of baud rate divisor.
  29.     o DHH High byte of baud rate divisor.
  30. */
  31. #define TXR             0       /*  Transmit register (WRITE) */
  32. #define RXR             0       /*  Receive register  (READ)  */
  33. #define IER             1       /*  Interrupt Enable          */
  34. #define IIR             2       /*  Interrupt ID              */
  35. #define LCR             3       /*  Line control              */
  36. #define MCR             4       /*  Modem control             */
  37. #define LSR             5       /*  Line Status               */
  38. #define MSR             6       /*  Modem Status              */
  39. #define DLL             0       /*  Divisor Latch Low         */
  40. #define DLH             1       /*  Divisor latch High        */
  41.  
  42.  
  43. /*-------------------------------------------------------------------*
  44.   Bit values held in the Line Control Register (LCR).
  45.     bit        meaning
  46.     ---        -------
  47.     0-1        00=5 bits, 01=6 bits, 10=7 bits, 11=8 bits.
  48.     2        Stop bits.
  49.     3        0=parity off, 1=parity on.
  50.     4        0=parity odd, 1=parity even.
  51.     5        Sticky parity.
  52.     6        Set break.
  53.     7        Toggle port addresses.
  54.  *-------------------------------------------------------------------*/
  55. #define NO_PARITY       0x00
  56. #define EVEN_PARITY     0x18
  57. #define ODD_PARITY      0x08
  58.  
  59.  
  60.  
  61. /*-------------------------------------------------------------------*
  62.   Bit values held in the Line Status Register (LSR).
  63.     bit        meaning
  64.     ---        -------
  65.     0        Data ready.
  66.     1        Overrun error - Data register overwritten.
  67.     2        Parity error - bad transmission.
  68.     3        Framing error - No stop bit was found.
  69.     4        Break detect - End to transmission requested.
  70.     5        Transmitter holding register is empty.
  71.     6        Transmitter shift register is empty.
  72.     7               Time out - off line.
  73.  *-------------------------------------------------------------------*/
  74. #define RCVRDY          0x01
  75. #define OVRERR          0x02
  76. #define PRTYERR         0x04
  77. #define FRMERR          0x08
  78. #define BRKERR          0x10
  79. #define XMTRDY          0x20
  80. #define XMTRSR          0x40
  81. #define TIMEOUT        0x80
  82.  
  83. /*-------------------------------------------------------------------*
  84.   Bit values held in the Modem Output Control Register (MCR).
  85.     bit         meaning
  86.     ---        -------
  87.     0        Data Terminal Ready. Computer ready to go.
  88.     1        Request To Send. Computer wants to send data.
  89.     2        auxillary output #1.
  90.     3        auxillary output #2.(Note: This bit must be
  91.             set to allow the communications card to send
  92.             interrupts to the system)
  93.     4        UART ouput looped back as input.
  94.     5-7        not used.
  95.  *------------------------------------------------------------------*/
  96. #define DTR             0x01
  97. #define RTS             0x02
  98. #define MC_INT        0x08
  99.  
  100.  
  101. /*------------------------------------------------------------------*
  102.   Bit values held in the Modem Input Status Register (MSR).
  103.     bit        meaning
  104.     ---        -------
  105.     0        delta Clear To Send.
  106.     1        delta Data Set Ready.
  107.     2        delta Ring Indicator.
  108.     3        delta Data Carrier Detect.
  109.     4        Clear To Send.
  110.     5        Data Set Ready.
  111.     6        Ring Indicator.
  112.     7        Data Carrier Detect.
  113.  *------------------------------------------------------------------*/
  114. #define CTS             0x10
  115. #define DSR             0x20
  116.  
  117.  
  118. /*------------------------------------------------------------------*
  119.   Bit values held in the Interrupt Enable Register (IER).
  120.     bit        meaning
  121.     ---        -------
  122.     0        Interrupt when data received.
  123.     1        Interrupt when transmitter holding reg. empty.
  124.     2        Interrupt when data reception error.
  125.     3        Interrupt when change in modem status register.
  126.     4-7        Not used.
  127.  *------------------------------------------------------------------*/
  128. #define RX_INT          0x01
  129.  
  130.  
  131. /*------------------------------------------------------------------*
  132.   Bit values held in the Interrupt Identification Register (IIR).
  133.     bit        meaning
  134.     ---        -------
  135.     0        Interrupt pending
  136.     1-2             Interrupt ID code
  137.             00=Change in modem status register,
  138.             01=Transmitter holding register empty,
  139.             10=Data received,
  140.             11=reception error, or break encountered.
  141.     3-7        Not used.
  142.  *------------------------------------------------------------------*/
  143. #define RX_ID           0x04
  144. #define RX_MASK         0x07
  145.  
  146.  
  147. /*
  148.     These are the port addresses of the 8259 Programmable Interrupt
  149.     Controller (PIC).
  150. */
  151. #define IMR             0x21   /* Interrupt Mask Register port */
  152. #define ICR             0x20   /* Interrupt Control Port       */
  153.  
  154.  
  155. /*
  156.     An end of interrupt needs to be sent to the Control Port of
  157.     the 8259 when a hardware interrupt ends.
  158. */
  159. #define EOI             0x20   /* End Of Interrupt */
  160.  
  161.  
  162. /*
  163.     The (IMR) tells the (PIC) to service an interrupt only if it
  164.     is not masked (FALSE).
  165. */
  166. #define IRQ3            0xF7  /* COM2 */
  167. #define IRQ4            0xEF  /* COM1 */
  168.  
  169.  
  170. /*
  171.     The (IMR) tells the (PIC) to service an interrupt only if it
  172.     is not masked (FALSE).
  173. */
  174. #define IRQ3            0xF7  /* COM2 */
  175. #define IRQ4            0xEF  /* COM1 */
  176.  
  177.  
  178. class serial
  179. {
  180.    int flag;
  181.    int  SetSerial();
  182.    int  SetOthers(int Parity, int Bits, int StopBit);
  183.    int  SetSpeed(int Speed);
  184.    int  SetPort(int Port);
  185.    void init_serial(void);
  186.    void comm_off(void);
  187. public:
  188.    serial(int Port, int Speed, int Parity, int Bits, int StopBit);
  189.    serial &operator<<( char ch );
  190.    serial &operator<<( char *str );
  191.    serial &operator>>( char &ch );
  192.    ~serial();
  193. };
  194.